package cn.itcast.service.cargo.impl;

import cn.itcast.dao.cargo.*;
import cn.itcast.domain.cargo.*;
import cn.itcast.service.cargo.PackingService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.*;

@Service
public class PackingServiceImpl implements PackingService {

    @Autowired
    private ContractDao contractDao;/*购销合同*/

    @Autowired
    private ContractProductDao contractProductDao;/*购销合同的货物*/

    @Autowired
    private ExtCproductDao extCproductDao; /*购销合同的附件*/

    @Autowired
    private PackingDao packingDao; /*装箱管理*/



    /*
     装箱管理分页
     */
    @Override
    public PageInfo<Packing> findByPage(PackingExample packingExample, int pageNum, int pageSize) {
        //设置开始页与页面大小
        PageHelper.startPage(pageNum,pageSize);
        //查询全部
        List<Packing> packingList = packingDao.selectByExample(packingExample);
        PageInfo<Packing> pageInfo = new PageInfo<>(packingList);
        return pageInfo;
    }


    //查询全部
    @Override
    public List<Packing> findAll(PackingExample packingExample) {
        List<Packing> packingList = packingDao.selectByExample(packingExample);
        return packingList;
    }

    @Override
    public void save(Packing packing) {
        //补充完整信息
        packing.setCreateTime(new Date());
        //装箱id
        packing.setPackingListId(UUID.randomUUID().toString());
        //0草稿    1已委托
        packing.setState((long) 0);
        packingDao.insert(packing);
    }

    @Override
    public void update(Packing packing) {
        packingDao.updateByPrimaryKeySelective(packing);
    }

    //根据主键查询
    @Override
    public Packing findById(String id) {
        return packingDao.selectByPrimaryKey(id);
    }



    //删除装箱管理
    @Override
    public void delete(String id) {

        packingDao.deleteByPrimaryKey(id);
    }

}
